package com.xms.sdk.query;

import com.xms.sdk.core.query.AggregateType;
import com.xms.sdk.core.query.DateGroupingType;

/**
 * <p>
 * DataFieldExpressionHelper
 * </p>
 *
 * @author migo
 * @since 2021/9/7
 */
public class DataFieldExpressionHelper {
    public static String getDateGroupingExpression(DateGroupingType dgt, String field)
    {
        switch (dgt)
        {
            case YEAR:
                field = String.format("EXTRACT(YEAR FROM TIMESTAMP %s)", field);
                break;

            case MONTH:
                field = String.format("EXTRACT(MONTH FROM TIMESTAMP %s)", field);
                break;

            case DAY:
                field = String.format("EXTRACT(DAY FROM TIMESTAMP %s)", field);
                break;

            case QUARTER:
                field = String.format("EXTRACT(QUARTER FROM TIMESTAMP %s)", field);
                break;

            case WEEK:
                field = String.format("EXTRACT(WEEK FROM TIMESTAMP %s)", field);
                break;
        }
        return field;
    }

    public static String getAggregationExpression(AggregateType aggtype, String field)
    {
        return String.format("%s(%s)", aggtype.text(), field);
    }
}
